package cn.kshost.zqyg.product.controller;

import cn.kshost.zqyg.model.entity.product.Category;
import cn.kshost.zqyg.model.entity.product.ProductSku;
import cn.kshost.zqyg.model.vo.common.Result;
import cn.kshost.zqyg.model.vo.common.ResultCodeEnum;
import cn.kshost.zqyg.model.vo.h5.IndexVo;
import cn.kshost.zqyg.product.service.CategoryService;
import cn.kshost.zqyg.product.service.ProductService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.swing.text.html.ObjectView;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/api/product")
@Tag(name = "H5首页接口")
public class IndexController {

    @Autowired
    private ProductService productService;

    @Autowired
    private CategoryService categoryService;
    @ApiOperationSupport
    @GetMapping("/index")
    public Result<IndexVo> index() {
        //获取分类列表
        List<Category> categoryList =  categoryService.getRootCategoryList();
        //获取sku列表
        List<ProductSku> productSkuList =  productService.getHotProductSkuList();;
        IndexVo indexVo = new IndexVo(categoryList, productSkuList);
        return Result.build(indexVo, ResultCodeEnum.SUCCESS);


    }
}
